package com.ruoyi.common.utils;

import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.ruoyi.common.constant.HttpStatus;

import java.io.Serializable;
import java.util.List;

/**
 * @author yjm
 * @date 2025/7/8
 */
public class PageParam<T> extends Page<T> implements Serializable {
    private static final long serialVersionUID = 1L;
    private Integer pageNum;
    private Integer pageSize;
    private String orderByColumn;
    private String isAsc = "asc";
    private OrderItem orderItem = new OrderItem();

    public void setPageNum(Integer pageNum) {
        this.pageNum = pageNum;
        if (pageNum != null) {
            super.setCurrent(pageNum);
        }
    }

    public void setPageSize(Integer pageSize) {
        this.pageSize = pageSize;
        if (pageSize != null) {
            super.setSize(pageSize);
        }
    }

    public void setOrderByColumn(String orderByColumn) {
        this.orderByColumn = orderByColumn;
        if (orderByColumn != null) {
            orderItem.setColumn(orderByColumn);
            if (super.orders().isEmpty()) {
                super.orders().add(orderItem);
            }
        }
    }

    public void setIsAsc(String isAsc) {
        this.isAsc = isAsc;
        if (isAsc != null) {
            orderItem.setAsc(isAsc.toLowerCase().equals("asc"));
            if (super.orders().isEmpty()) {
                super.orders().add(orderItem);
            }
        }
    }

    @Override
    @JsonIgnore
    public long getCurrent() {
        return super.getCurrent();
    }

    @Override
    @JsonIgnore
    public List<T> getRecords() {
        return null;
    }

    @Override
    @JsonIgnore
    public long getSize() {
        return super.getSize();
    }

    @Override
    @JsonIgnore
    public long getPages() {
        return super.getPages();
    }

    public List<T> getRows() {
        return super.getRecords();
    }

    public int getCode()
    {
        return HttpStatus.SUCCESS;
    }

    public Integer getPageNum() {
        return pageNum;
    }

    public Integer getPageSize() {
        return pageSize;
    }
}